program HexagonalNumbers;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Math;

var
  f, g: TextFile;
  answer: Extended;
  T: Word;
  N, X, Y: Integer;



procedure ReadData;
begin
  Readln(f, N, X, Y);
end;

function HexagonalNumber(n: Integer): Integer;
begin
  Result := n * ((n shl 1) - 1);
end;

function BinomialCoff(N, K: Int64): Extended;
var
  L: Int64;

begin
  if N < K then
    Result:= 0      // Error
  else begin
    if K > N - K then
      K:= N - K;    // Optimization
    Result:= 1;
    L:= 0;
    while L < K do begin
      Result:= Result * (N - L);
      Inc(L);
      Result:= Result / L;
    end;
  end;
end;

function CalculateProb(M, p, z: Integer): Extended;
var
  i: Integer;
  bs: Extended;
begin
  bs := exp(M * ln(2));
  //if M <= p shl 1 then begin
    Result := 0;
    for i := M downto z do
      Result := Result + BinomialCoff(M, i) / bs;
  {end else begin

  end;}
  if Result < 1e-6 then
    Result := 0;
end;

procedure ProcessData;
var
  previousHexahonalIndex, hexahonalIndex, hexNum, previous, m, p, s, delta: Integer;
begin
  hexahonalIndex := Ceil((1 + sqrt(1 + 8 * n)) / 4);
  previousHexahonalIndex := trunc((1 + sqrt(1 + 8 * n)) / 4);
  hexNum := HexagonalNumber(hexahonalIndex);
  previous := HexagonalNumber(previousHexahonalIndex);
  if (N = hexNum) then begin
    if (abs(x) + y) shr 1 <= hexahonalIndex - 1 then
      answer := 1
    else
      answer := 0;
    Exit;
  end;
  if (N = hexNum - 1) then begin
    if (x = 0) and (y = (hexahonalIndex - 1) shl 1) then begin
      answer := 0;
      Exit;
    end;
    if (abs(x) + y) shr 1 <= hexahonalIndex - 1 then
      answer := 1
    else
      answer := 0;
    Exit;
  end;
  if (abs(x) + y) shr 1 <= previousHexahonalIndex - 1 then begin
    answer := 1;
    Exit;
  end;
  if (abs(x) + y) shr 1 > hexahonalIndex - 1 then begin
    answer := 0;
    Exit;
  end;
  m := N - previous;
  //s := abs(x) + y;
  p := previousHexahonalIndex;
  if N = previous + 1 then begin
    if (y = 0) and (abs(x) = (hexahonalIndex - 1) shl 1)  then
      answer := 0.5
    else
      answer := 0;
    Exit;
  end;
  if (m <= p shl 1) then begin
    answer := CalculateProb(m, p, y + 1);
    Exit;
  end;
  if (m > p shl 1) then begin
    delta := m - p shl 1;
    if (y + 1 <= delta) then begin
      answer := 1;
      Exit;
    end;
    answer := CalculateProb(m - (delta shl 1), p, y + 1 - delta);
    Exit;

  end;




  //if (N = hexNum) or (N = hexNum - 1) then

  answer := 42;
end;

procedure Test;
var
  M, z, i: Integer;
  Result, bs: Extended;
begin
  M := 100;//1009;
  Z := 1;
  bs := exp(M * ln(2));
  //if M <= p shl 1 then begin
    Result := 0;
    for i := M downto 0 do begin
      writeln(BinomialCoff(M, i), ' ');
      Result := Result + BinomialCoff(M, i);
    end;
  Writeln('Result = ', Result, ' bs = ', bs);
  Readln;
end;

procedure OutputVerdict(casenum: Word);
begin
  writeln(g, 'Case #', casenum, ': ', answer:11:11);
  writeln('Case #', casenum, ': ', answer:6:6);
end;

var
  i: Word;
  s: String;

begin
  //Test;
  //Exit;
  try
    for i := 1 to 20 do begin
      Write(HexagonalNumber(i), ', ');
    end;
    writeln;
    writeln('Finished');
    Readln;
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E: Exception do begin
      Writeln(E.ClassName, ': ', E.Message);
      readln;
    end;
  end;
end.
